﻿//文件指定编译编码UTF-8
#pragma execution_character_set("utf-8")

/**
*    @file:    main.cpp
*    @brief:
*    @author:  sanshi522@163.com
*    @date:    2025-04-08  10:15
*/
#include <QCoreApplication>
#include <QThread>
#include <progressmanage.h>
#include <QDebug>
#include <QCoreApplication>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    ProgressManage progressManage;
    progressManage.enableDebugPriv();
//    if(!progressManage.enableDebugPriv()){
//        qDebug() << "权限提升失败";
//    }
    int testCount = 100000;
    while (testCount > 0) {
        testCount--;
        string processPath = QString("C:/Program Files/GeovisInstallerStudio/GeovisInstallerStudio/GeovisInstallerStudio.exe").toStdString();
        DWORD processId;
        if(progressManage.getProcessIdByPath(processPath,processId)){
            //获取本程序内存
            qDebug() << processId;
            uint64_t time;
            progressManage.getProcessTimeById(processId,time);
            qDebug() << QString("运行时长:%1").arg(time);
            float cpuUsage;
            progressManage.get_cpu_usage(processId,cpuUsage);
            qDebug() << QString("CUP使用率:%1").arg(cpuUsage);
            uint64_t memUse,vmemUse;
            progressManage.get_memory_usage(processId,memUse,vmemUse);
            qDebug() << QString("内存使用:%1，%2").arg(memUse).arg(vmemUse);
            uint64_t ioR,ioW;
            progressManage.get_io_bytes(processId,ioR,ioW);
            qDebug() << QString("IO读:%1，IO写%2").arg(ioR).arg(ioW);
        }else{
            qDebug()<< "进程获取失败";
        }
        ulong applicationPid = QCoreApplication::applicationPid();
        uint64_t memUse;
        uint64_t vmemUse;
        progressManage.get_memory_usage(applicationPid,memUse,vmemUse);
        qDebug()<< QString("本程序内存使用情况:%1(%2MB)").arg(memUse).arg(memUse/1024.0/1024.0);
        QThread::msleep(100);
    }
    return a.exec();
}
